<template>
  <BasicModal v-bind="$attrs" @register="registerModal" title="下载二维码" @ok="handleSubmit" width="600px">
    <!-- <BasicForm @register="registerForm" /> -->
    <ImagePreview :image-list="[{ src: images, width: 200 }]" />
  </BasicModal>
</template>
<script lang="ts" setup>
  import { ref, computed, unref, reactive } from "vue"
  import { BasicModal, useModalInner } from "/@/components/Modal"
  import { BasicForm, useForm } from "/@/components/Form"
  import { categoryFormSchema } from "./table.data"
  import { genTableQrcode } from "./table.api"
  import { ImagePreview } from "/@/components/Preview/index"
  const emit = defineEmits(["success", "register"])
  const tenantId = ref(null)
  const images = ref()
  // const [registerForm, { resetFields, setFieldsValue, validate }] = useForm({
  //   schemas: categoryFormSchema,
  //   showActionButtonGroup: false,
  //   labelCol: {
  //     xs: { span: 24 },
  //     sm: { span: 4 },
  //   },
  //   wrapperCol: {
  //     xs: { span: 24 },
  //     sm: { span: 18 },
  //   },
  // });
  //表单赋值
  const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
    // await resetFields();
    const { id, tenantId } = data.record || {}
    setModalProps({ confirmLoading: false, height: 500, draggable: false, canFullscreen: false })
    const qrcodeBase64 = await genTableQrcode({ id })
    images.value = `data:image/png;base64,${qrcodeBase64}`
    tenantId.value = data?.tenantId
  })

  async function handleSubmit() {
    try {
      // const values = await validate();
      // values.tenantId = tenantId.value
      // setModalProps({ confirmLoading: true });
      // await saveOrUpdateCategory(values, isUpdate.value);
      closeModal()
    } finally {
      setModalProps({ confirmLoading: false })
    }
  }
</script>
